package cn.lbd.datastructure;

import java.util.Stack;

public class ReverseOutput {

    public static void reverseOutput(HeroNode head){

        Stack<HeroNode> stack = new Stack<>();
        HeroNode temp = head.next;
        while(true){
            if (head.next == null){
                return;
            }
            if (temp == null){
                break;
            }
            stack.push(temp);
            temp = temp.next;
        }

        while (true){
            if (stack.empty()){
                return;
            }else {
                HeroNode pop = stack.pop();
                System.out.println(pop);
            }
        }

    }

    public static void main(String[] args) {
        HeroNode heroNode1 = new HeroNode(1, "宋江", "及时雨");
        HeroNode heroNode2 = new HeroNode(2, "卢俊义", "玉麒麟");
        HeroNode heroNode3 = new HeroNode(3, "吴用", "智多星");
        HeroNode heroNode4 = new HeroNode(6, "林冲", "豹子头");

        SingleLinkedList singleLinkedList = new SingleLinkedList();

        singleLinkedList.add(heroNode1);
        singleLinkedList.add(heroNode2);
        singleLinkedList.add(heroNode3);
        singleLinkedList.add(heroNode4);

        reverseOutput(singleLinkedList.getHead());
    }


}



class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }

    @Override
    public String toString() {
        return "ListNode{" +
                "val=" + val +
                '}';
    }
}
